
function hidehud(name)
	for k, v in pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do
		if name == v then return false end
	end
end

function GetCurWepTotalAmmo()
	MySelf = LocalPlayer()
 
	actwep = MySelf:GetActiveWeapon()
	if ( ! actwep ) then return -1 end
	if pcall(function() actwep:GetPrimaryAmmoType() end)
	then
		return MySelf:GetAmmoCount(actwep:GetPrimaryAmmoType())
	else return -1 end
end

function drawHealth()

	-- Get the team color
	local teamcol
	
	if LocalPlayer():Team() == 1 then 
		teamcol = Color( 20, 20, 75, 180 ) 
	elseif LocalPlayer():Team() == 2 then 
		teamcol = Color( 75, 20, 20, 180 ) 
	else 
		teamcol = Color( 20, 20, 20, 180 ) 
	end
	--[[
	if LocalPlayer():Health() > LocalPlayer():GetNWInt("maxhealth" ) then
		LocalPlayer():SetNWInt("maxhealth",LocalPlayer():Health())
	end
	]]
	
	local TeamScore = team.GetScore(LocalPlayer():Team())
	local Kills = LocalPlayer():Frags()
	local Health = math.Round((LocalPlayer():Health()/LocalPlayer():GetNWInt("maxhealth"))*100)
	local MoveH = ((Health/100) * 300) -1
		
	-- Draw the HUD
		
	draw.RoundedBox( 0, 100, (ScrH() - 150), 305, 96, Color(140, 140, 140, 200) )
	draw.RoundedBox( 0, 103, (ScrH() - 148), MoveH, 28, Color( ( Health * -2.55 ) + 255, Health * 2.55, 0 ) )
	draw.SimpleTextOutlined("HP: "..Health,"ScoreboardText", 250, (ScrH() - 134), Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(40, 40, 40, 255))
	if LocalPlayer():GetActiveWeapon() then
	if LocalPlayer():GetActiveWeapon() and GetCurWepTotalAmmo() != -1 then
		draw.SimpleTextOutlined(LocalPlayer():GetActiveWeapon():Clip1().."/"..GetCurWepTotalAmmo(),"ScoreboardText",  300, (ScrH() - 71), Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(40, 40, 40, 255))	
	end
	end
	
	
	-- PERK STATUS
	
	if LocalPlayer():GetNWString("class") == "support" then
		local Len = 100
		if LocalPlayer():GetNetworkedBool( "MedFired" ) == true then
			Len = math.Clamp(((CurTime() - LocalPlayer():GetNetworkedFloat( "MedRel" ))*10)+100,0,100)
		end
		draw.RoundedBox( 0, 202, (ScrH() - 118), Len*2, 30, Color(0, 140, 0, 255) )
		draw.SimpleTextOutlined("Medkit: "..math.Round(Len).."% Ready","ScoreboardText", 301, (ScrH() - 101), Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(40, 40, 40, 255))	
	end
	if LocalPlayer():GetNWString("class") == "marksman" then
		local Len = 100
		
		if Perk.Cooldown - CurTime() <= 20 then
			Len = (-math.Clamp(Perk.Cooldown - CurTime(),0,20) + 20)*(100/20)
		else
			Len = (Perk.Cooldown - 20 - CurTime())*(100/(LocalPlayer():GetNWInt("marksmanlvl")*3))
		end
		
		draw.RoundedBox( 0, 202, (ScrH() - 118), Len*2, 30, Color(0, 140, 0, 255) )
		draw.SimpleTextOutlined(Perk.Type..": "..math.Round(Len).."% Ready","ScoreboardText", 301, (ScrH() - 101), Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(40, 40, 40, 255))	
	end
	if LocalPlayer():GetNWString("class") == "assassin" then
		local Len = 100
		
		if Perk.Cooldown - CurTime() <= 20 then
			Len = (-math.Clamp(Perk.Cooldown - CurTime(),0,20) + 20)*(100/20)
		else
			Len = (Perk.Cooldown - 20 - CurTime())*(100/(LocalPlayer():GetNWInt("assassinlvl")*3))
		end
			
		draw.RoundedBox( 0, 202, (ScrH() - 118), Len*2, 30, Color(0, 140, 0, 255) )
		draw.SimpleTextOutlined(Perk.Type..": "..math.Round(Len).."% Ready","ScoreboardText", 301, (ScrH() - 101), Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(40, 40, 40, 255))	
	end
	if LocalPlayer():GetNetworkedString("class") == "soldier" then

	end
	if LocalPlayer():Team() == 1 or LocalPlayer():Team() == 2 then		
		local planex = (ScrW() - (ScrW()/10))
		local planey = 0

		draw.RoundedBox( 0, planex, planey, (ScrW()/10), (ScrW()/10), teamcol)
		for k, v in pairs(player.GetAll()) do
			if v:Team() == LocalPlayer():Team() and v != LocalPlayer() then
				local classcol
			
				if v:GetNWString("class") == "soldier" then 
					classcol = Color( 0, 255, 0, 255 ) 
				elseif v:GetNWString("class") == "support" then 
					classcol = Color( 255, 150, 0, 255 ) 
				elseif v:GetNWString("class") == "assassin" then 
					classcol = Color( 255, 255, 0, 255 ) 
				elseif v:GetNWString("class") == "marksman" then 
					classcol = Color( 139, 69, 19, 255 ) 
				else
					classcol = Color( 110, 110, 110, 255 )
				end
				local dir = Vector(LocalPlayer():WorldToLocal(v:GetPos()):GetNormalized().y*-1,LocalPlayer():WorldToLocal(v:GetPos()):GetNormalized().x,0)
				local pos = Vector(0,0,0)
				pos.x = (dir.x*(LocalPlayer():GetPos():Distance(v:GetPos())/20)) + (ScrW()/20)
				pos.y = ((dir.y*(LocalPlayer():GetPos():Distance(v:GetPos())/20))*-1) + (ScrW()/20)
				if ( pos.x < (ScrW()/10) and pos.x > 0 and pos.y < (ScrW()/10) and pos.y > 0 ) then
					draw.RoundedBox( 0, pos.x + planex - 2, pos.y + planey - 2, 4, 4, classcol)
				end
			else
				draw.RoundedBox( 4, planex + (ScrW()/20)-4, planey + (ScrW()/20)-4, 8, 8, Color(255, 255, 255, 255))
			end
		end
	end
		
	--[[if (TeamKills ~= 0) then
		draw.RoundedBox( 2, 202-(MoveH/2), (ScrH() - 118), MoveH+1, 26, Color( ((TeamKills/5) * -200) + 200, ((TeamKills/5) * 200), 0, 180 ) )
	end
	
	draw.DrawText( tostring(team.TotalFrags(LocalPlayer():Team())).."/"..tostring(team.TotalDeaths(LocalPlayer():Team())), "ScoreboardText", 207.5, (ScrH() - 116), Color( 255, 255, 255, 255 ), 1 )
	draw.DrawText( "Team: " .. tostring(team.GetName(LocalPlayer():Team())), "ScoreboardText", 55, (ScrH() - 70), Color( 200, 200, 200, 255 ), 0 )
	draw.DrawText( "Ping: " .. tostring(LocalPlayer():Ping()), "ScoreboardText", 55, (ScrH() - 50), Color( 200, 200, 200, 255 ), 0 )
	
	-- Aim Entity
	if LocalPlayer():GetEyeTraceNoCursor().Entity:IsValid() then
		if LocalPlayer():GetEyeTraceNoCursor().Entity:GetClass() == "player" || LocalPlayer():GetEyeTraceNoCursor().Entity:GetClass() == "npc_*" then

			-- Get the team color
			if LocalPlayer():GetEyeTraceNoCursor().Entity:Team() == 1 then 
				local teamcol = Color( 0, 0, 255, 180 ) 
			elseif LocalPlayer():GetEyeTraceNoCursor().Entity:Team() == 2 then 
				local teamcol = Color( 255, 0, 0, 180 ) 
			else 
				local teamcol = Color( 0, 0, 0, 180 ) 
			end
			
			local TeamKills = LocalPlayer():GetEyeTraceNoCursor().Entity:Team():TotalFrags() / LocalPlayer():GetEyeTraceNoCursor().Entity:Team():TotalDeaths() -- Get Kill / Death ratio
			local Kills = LocalPlayer():GetEyeTraceNoCursor().Entity:Frags()
			local MoveH = ((TeamKills/5) * 150) - 1
			
			draw.RoundedBox( 0, ScrW()-355, (ScrH() - 120), 305, 30, teamcol )
			draw.RoundedBox( 0, ScrW()-355, (ScrH() - 90), 305, 60, teamcol )
			if (TeamKills ~= 0) then
				draw.RoundedBox( 2, ScrW()-202-(MoveH), (ScrH() - 118), MoveH+1, 26, Color( ((Kills/5) * -200) + 200, 0, ((Kills/5) * 200), 180 ) )
			end
			
			draw.DrawText( tostring(LocalPlayer():GetEyeTraceNoCursor().Entity:Team():TotalFrags()).."/"..tostring(LocalPlayer():GetEyeTraceNoCursor().Entity:Team():TotalDeaths()), "ScoreboardText", ScrW()-207.5, (ScrH() - 116), Color( 255, 255, 255, 255 ), 1 )
			draw.DrawText( "Rank: " .. tostring(team.GetName(LocalPlayer():GetEyeTraceNoCursor().Entity:Team())), "ScoreboardText", ScrW()-350, (ScrH() - 70), Color( 200, 200, 200, 255 ), 0 )
			draw.DrawText( "Ping: " .. tostring(LocalPlayer():GetEyeTraceNoCursor().Entity:Ping()), "ScoreboardText", ScrW()-350, (ScrH() - 50), Color( 200, 200, 200, 255 ), 0 )
		end
	end ]]--
end

hook.Add("HUDPaint","DrawHealth",drawHealth)
hook.Add("HUDShouldDraw", "hidehud", hidehud)